package br.com.itx.drools.einstein;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.drools.RuleBase;
import org.drools.rule.Rule;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("factories")
@Scope(ScopeType.APPLICATION)
public class Factories implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Factory("cores")
	public Cor[] getCores() {
		return Cor.values();
	}
	
	@Factory("nacionalidades")
	public Nacionalidade[] getNacionalidades() {
		return Nacionalidade.values();
	}
	
	@Factory("carros")
	public Carro[] getCarros() {
		return Carro.values();
	}
	
	@Factory("animais")
	public Animal[] getAnimais() {
		return Animal.values();
	}
	
	@Factory("bebidas")
	public Bebida[] getBebidas() {
		return Bebida.values();
	}
	
	@Factory("regras")
	public List<String> getRegras() {
		RuleBase ruleBase = (RuleBase) Component.getInstance("ruleBase");
		Rule[] rules = ruleBase.getPackage("defaultpkg").getRules();
		List<String> names = new ArrayList<String>();
		for (int i = 0; i < rules.length; i++) {
			String n = rules[i].getName();
			if (!n.startsWith("_")) {
				names.add(n);
			}
		}
		return names;
	}
	
}
